<!-- 财务指标 -->
<script lang="ts" setup>
import {
  addFinanceIndexThreshold,
  listFinanceIndexThreshold,
  updateFinanceIndexThreshold
} from "@/api/system/financeIndexThreshold";
import { onMounted, getCurrentInstance, ref, reactive, toRefs } from "vue";

const { proxy } = getCurrentInstance();
const loading = ref(true);
const total = ref(0);
const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    totalCostThreshold: undefined,
    params: {},
  },
});
let hasRes = ref(false);
const { queryParams } = toRefs(data);
let financeIndexThresholdFormRef = ref({
  totalCostThreshold: "",
  collaborateCostThreshold: "",
  expertCostThreshold: "",
  meetingCostThreshold: "",
  laborServiceCostThreshold: "",
  businessEntertainCostThreshold: "",
  leaseCostThreshold: "",
  travelCostThreshold: "",
  // externalServiceCostThreshold: "",
  // otherCostThreshold: "",
  // artificialcCostThreshold: "",
});
const Save = async () => {
  if (hasRes) {
    let res = await updateFinanceIndexThreshold(
      financeIndexThresholdFormRef.value
    );
    if(res.code == 200){
      proxy?.$modal.msgSuccess("操作成功");
    }
  } else {
    let res = await addFinanceIndexThreshold(
      financeIndexThresholdFormRef.value
    );
    if(res.code == 200){
      proxy?.$modal.msgSuccess("操作成功");
    }
  }
};
const getList = async () => {
  loading.value = true;
  const res = await listFinanceIndexThreshold(queryParams.value);
  if (res.rows.length) {
    financeIndexThresholdFormRef.value = res.rows[0];
    hasRes.value = true;
  }
  total.value = res.total;
  loading.value = false;
};
onMounted(() => {
  getList();
});
</script>

<template>
  <VCard>
    <VCardText class="py-10">
      <VRow class="match-height">
        <VCol cols="12" md="4">
          <VRow no-gutters>
            <VCol cols="12" md="5" class="d-flex align-items-center">
              <label
                class="v-label text-body-2 text-high-emphasis"
                for="firstName"
                >总成本费用收入比阈值(%)</label
              >
            </VCol>
            <VCol cols="12" md="7">
              <AppTextField
                v-model="financeIndexThresholdFormRef.totalCostThreshold"
                label=""
                placeholder="请输入总成本费用收入比阈值"
                density="compact"
                :rules="[requiredValidator]"
              />
            </VCol>
          </VRow>
        </VCol>
        <!-- <VCol cols="12" md="4">
          <VRow no-gutters>
            <VCol cols="12" md="5" class="d-flex align-items-center">
              <label
                class="v-label text-body-2 text-high-emphasis"
                for="firstName"
                >人工成本费收入比阈值(%)</label
              >
            </VCol>
            <VCol cols="12" md="7">
              <AppTextField
                v-model="financeIndexThresholdFormRef.artificialcCostThreshold"
                label=""
                placeholder="请输入人工成本费用收入比阈值"
                :rules="[requiredValidator]"
                density="compact"
              />
            </VCol>
          </VRow>
        </VCol> -->
        <VCol cols="12" md="4">
          <VRow no-gutters>
            <VCol cols="12" md="5" class="d-flex align-items-center">
              <label
                class="v-label text-body-2 text-high-emphasis"
                for="firstName"
                >协作费收入比阈值(%)</label
              >
            </VCol>
            <VCol cols="12" md="7">
              <AppTextField
                v-model="financeIndexThresholdFormRef.collaborateCostThreshold"
                label=""
                :rules="[requiredValidator]"
                placeholder="请输入协作费收入比阈值"
                density="compact"
              />
            </VCol>
          </VRow>
        </VCol>
        <VCol cols="12" md="4">
          <VRow no-gutters>
            <VCol cols="12" md="5" class="d-flex align-items-center">
              <label
                class="v-label text-body-2 text-high-emphasis"
                for="firstName"
                >专家费收入比阈值(%)</label
              >
            </VCol>
            <VCol cols="12" md="7">
              <AppTextField
                v-model="financeIndexThresholdFormRef.expertCostThreshold"
                label=""
                :rules="[requiredValidator]"
                placeholder="请输入专家费收入比阈值"
                density="compact"
              />
            </VCol>
          </VRow>
        </VCol>
        <VCol cols="12" md="4">
          <VRow no-gutters>
            <VCol cols="12" md="5" class="d-flex align-items-center">
              <label
                class="v-label text-body-2 text-high-emphasis"
                for="firstName"
                >会议费收入比阈值(%)</label
              >
            </VCol>
            <VCol cols="12" md="7">
              <AppTextField
                v-model="financeIndexThresholdFormRef.meetingCostThreshold"
                label=""
                :rules="[requiredValidator]"
                placeholder="请输入会议费收入比阈值"
                density="compact"
              />
            </VCol>
          </VRow>
        </VCol>
        <VCol cols="12" md="4">
          <VRow no-gutters>
            <VCol cols="12" md="5" class="d-flex align-items-center">
              <label
                class="v-label text-body-2 text-high-emphasis"
                for="firstName"
                >劳务费收入比阈值(%)</label
              >
            </VCol>
            <VCol cols="12" md="7">
              <AppTextField
                v-model="financeIndexThresholdFormRef.laborServiceCostThreshold"
                label=""
                :rules="[requiredValidator]"
                placeholder="请输入劳务费收入比阈值"
                density="compact"
              />
            </VCol>
          </VRow>
        </VCol>
        <VCol cols="12" md="4">
          <VRow no-gutters>
            <VCol cols="12" md="5" class="d-flex align-items-center">
              <label
                class="v-label text-body-2 text-high-emphasis"
                for="firstName"
                >业务招待费收入比阈值(%)</label
              >
            </VCol>
            <VCol cols="12" md="7">
              <AppTextField
                v-model="
                  financeIndexThresholdFormRef.businessEntertainCostThreshold
                "
                label=""
                :rules="[requiredValidator]"
                placeholder="请输入业务招待费收入比阈值"
                density="compact"
              />
            </VCol>
          </VRow>
        </VCol>
        <VCol cols="12" md="4">
          <VRow no-gutters>
            <VCol cols="12" md="5" class="d-flex align-items-center">
              <label
                class="v-label text-body-2 text-high-emphasis"
                for="firstName"
                >租赁费收入比阈值(%)</label
              >
            </VCol>
            <VCol cols="12" md="7">
              <AppTextField
                v-model="financeIndexThresholdFormRef.leaseCostThreshold"
                label=""
                :rules="[requiredValidator]"
                placeholder="请输入租赁费收入比阈值"
                density="compact"
              />
            </VCol>
          </VRow>
        </VCol>
        <VCol cols="12" md="4">
          <VRow no-gutters>
            <VCol cols="12" md="5" class="d-flex align-items-center">
              <label
                class="v-label text-body-2 text-high-emphasis"
                for="firstName"
                >差旅费收入比阈值(%)</label
              >
            </VCol>
            <VCol cols="12" md="7">
              <AppTextField
                v-model="financeIndexThresholdFormRef.travelCostThreshold"
                label=""
                :rules="[requiredValidator]"
                placeholder="请输入差旅费收入比阈值"
                density="compact"
              />
            </VCol>
          </VRow>
        </VCol>
        <!-- <VCol cols="12" md="4">
          <VRow no-gutters>
            <VCol cols="12" md="5" class="d-flex align-items-center">
              <label
                class="v-label text-body-2 text-high-emphasis"
                for="firstName"
                >外部服务费收入比阈值(%)</label
              >
            </VCol>
            <VCol cols="12" md="7">
              <AppTextField
                v-model="
                  financeIndexThresholdFormRef.externalServiceCostThreshold
                "
                label=""
                :rules="[requiredValidator]"
                placeholder="请输入外部服务费收入比阈值"
                density="compact"
              />
            </VCol>
          </VRow>
        </VCol> -->
        <!-- <VCol cols="12" md="4">
          <VRow no-gutters>
            <VCol cols="12" md="5" class="d-flex align-items-center">
              <label
                class="v-label text-body-2 text-high-emphasis"
                for="firstName"
                >其他费用收入比阈值(%)</label
              >
            </VCol>
            <VCol cols="12" md="7">
              <AppTextField
                v-model="financeIndexThresholdFormRef.otherCostThreshold"
                label=""
                :rules="[requiredValidator]"
                placeholder="请输入其他费用收入比阈值"
                density="compact"
              />
            </VCol>
          </VRow>
        </VCol> -->
        <VCol cols="12" md="4" class="display_flex-end">
          <VBtn color="primary" density="compact" @click="Save()"> 保存 </VBtn>
        </VCol>
      </VRow>
    </VCardText>
  </VCard>
</template>

<style lang="scss">
.display_flex-end {
  display: flex;
  align-items: flex-end;
  gap: 15px;
}

.mb-1 {
  margin-block-end: 0 !important;
}
</style>
